package BackTrack.万诺;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static MyUtils.MHUtils.*;

/*
    30分钟

    2226 要cI从0开始‘扫描’
    之后转 num = parseInt

    3个相同 层序深搜
    f(cI+1)
    f(cI+1)
    f(cI+1)

    电话号 IP
        都是 起点[0] 必用且必是第一个
 */
public class 电话号码的字母组合17 {
    @Test
    public void test() {
        System.out.println("RES: " + letterCombinations("23"));
    }

    List<String> res = new ArrayList<>();
    StringBuilder tmp = new StringBuilder();
    String s;
    public List<String> letterCombinations(String digits) {
        if(digits=="" || digits.length()==0)return res;//空
        s = digits;
        int cI = 0; // digit='222' 从第1个2开始
        bT(cI);
        return res;
    }

    char[][] c =
    {
        {},
        {'a','b','c'},
        {'d','e','f'},
        {'g','h','i'},
        {'j','k','l'},
        {'m','n','o'},
        {'p','q','r','s'},
        {'t','u','v'},
        {'w','x','y','z'}
    };

    private void bT(int cI) {
        if(tmp.length() == s.length()) {
            res.add(new String(tmp.toString()));
            return;
        }
        int step = Integer.parseInt(s.charAt(cI)+"")-1;
        for (int i = 0; i < c[step].length; i++) {
            tmp.append(c[step][i]);
            //一层一个:类似拿与不拿
            bT(cI+1);
            tmp.deleteCharAt(tmp.length()-1);
        }
    }
}
